<cfmodule template="../../tag/layout.cfm">
<cfinclude template="../../inc/lib.cfm">
<script type="text/javascript" src="assets/accounting/accounting.min.js"></script>
<script type="text/javascript">
	accounting.settings = {
	currency: {
		symbol : "￥",   // default currency symbol is '$'
		format: "%s%v", // controls output: %s = symbol, %v = value/number (can be object: see below)
		decimal : ".",  // decimal point separator
		thousand: ",",  // thousands separator
		precision : 2   // decimal places
	},
	number: {
		precision : 0,  // default precision on numbers is 0
		thousand: ",",
		decimal : "."
	}
}

</script>
<!--- 表格显示 --->
<div id="grid"></div>
<div id="toolbar" style="display: none;">
	<form id="searchForm">
		<table>
			<tr>
				<td>
					产品编号 <input name="procode" style="width: 120px;" />
					产品名称 <input name="prochsname" style="width: 180px;" />
					全拼音码 <input name="propysimplespell" style="width: 120px;" />
					简拼音码 <input name="propysimplespell" style="width: 120px;" />
				</td>
			</tr>
			<tr>
				<td>
					销售状态
					<select class="easyui-combobox" name="issale" data-options="panelHeight:'auto'" style="width:100px;">
						<option value="">选择销售状态</option>
						<option value="0">下架</option>
				        <option value="1">上架</option>
					</select>
					审核状态
					<select class="easyui-combobox" name="status" data-options="panelHeight:'auto'" style="width:100px;">
						<option value="">选择审核状态</option>
						<option value="0">无效</option>
				        <option value="1">有效</option>
				        <option value="2">退回</option>
				        <option value="3">删除</option>
					</select>
					时间范围
					<input name="created_ge"  class="easyui-datebox" style="width:100px"/>
					-
					<input name="created_le"  class="easyui-datebox" style="width:100px"/>
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom',plain:true" onclick="grid.datagrid('load',fw.serializeObject($('#searchForm')));">过滤</a>
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom_out',plain:true" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a>
				</td>
			</tr>
		</table>
	</form>
	<table>
		<tr>
			<td>

		        <a href="#" class="easyui-menubutton" data-options="menu:'#mm1',plain:true">首页</a>
		        <div id="mm1">
			    	<div data-options="iconCls:'icon-redo'" onclick="BatFun('indexbat',1);">批量首页</div>
			        <div data-options="iconCls:'icon-undo'" onclick="BatFun('indexbat',0);">取消首页</div>
			    </div>

		        <a href="#" class="easyui-menubutton" data-options="menu:'#mm2',plain:true">推荐</a>
		        <div id="mm2">
			    	<div data-options="iconCls:'icon-redo'" onclick="BatFun('commendbat',1);">批量推荐</div>
			        <div data-options="iconCls:'icon-undo'" onclick="BatFun('commendbat',0);">取消推荐</div>
			    </div>

		        <a href="#" class="easyui-menubutton" data-options="menu:'#mm3',plain:true">滚动</a>
		        <div id="mm3">
			    	<div data-options="iconCls:'icon-redo'" onclick="BatFun('scrollbat',1);">批量滚动</div>
			        <div data-options="iconCls:'icon-undo'" onclick="BatFun('scrollbat',0);">取消滚动</div>
			    </div>

		        <a href="#" class="easyui-menubutton" data-options="menu:'#mm4',plain:true">评论</a>
		        <div id="mm4">
			    	<div data-options="iconCls:'icon-redo'" onclick="BatFun('commentbat',1);">批量评论</div>
			        <div data-options="iconCls:'icon-undo'" onclick="BatFun('commentbat',0);">取消评论</div>
			    </div>

			    <a href="#" class="easyui-menubutton" data-options="menu:'#mm5',plain:true">置顶</a>
		        <div id="mm5">
			    	<div data-options="iconCls:'icon-redo'" onclick="BatFun('topbat',1);">批量置顶</div>
			        <div data-options="iconCls:'icon-undo'" onclick="BatFun('topbat',0);">取消置顶</div>
			    </div>

			    <a href="#" class="easyui-menubutton" data-options="menu:'#mm6',plain:true">新品</a>
		        <div id="mm6">
			    	<div data-options="iconCls:'icon-redo'" onclick="BatFun('newbat',1);">批量新品</div>
			        <div data-options="iconCls:'icon-undo'" onclick="BatFun('newbat',0);">取消新品</div>
			    </div>

			    <a href="#" class="easyui-menubutton" data-options="menu:'#mm7',plain:true">热销</a>
		        <div id="mm7">
			    	<div data-options="iconCls:'icon-redo'" onclick="BatFun('hotbat',1);">批量热销</div>
			        <div data-options="iconCls:'icon-undo'" onclick="BatFun('hotbat',0);">取消热销</div>
			    </div>

			    <a href="#" class="easyui-menubutton" data-options="menu:'#mm8',plain:true">特色</a>
		        <div id="mm8">
			    	<div data-options="iconCls:'icon-redo'" onclick="BatFun('specialbat',1);">批量特色</div>
			        <div data-options="iconCls:'icon-undo'" onclick="BatFun('specialbat',0);">取消特色</div>
			    </div>

			    <a href="#" class="easyui-menubutton" data-options="menu:'#mm9',plain:true">频道</a>
		        <div id="mm9">
			    	<div data-options="iconCls:'icon-redo'" onclick="BatFun('channellbat',1);">频道主打</div>
			        <div data-options="iconCls:'icon-undo'" onclick="BatFun('channellbat',0);">取消主打</div>
			    </div>

			    <a href="#" class="easyui-menubutton" data-options="menu:'#mm10',plain:true">销售</a>
		        <div id="mm10">
			    	<div data-options="iconCls:'icon-redo'" onclick="BatFun('salebat',1);">上架</div>
			        <div data-options="iconCls:'icon-undo'" onclick="BatFun('salebat',0);">下架</div>
			    </div>

			    <a href="#" class="easyui-menubutton" data-options="menu:'#mm11',plain:true">审核</a>
		        <div id="mm11">
			    	<div data-options="iconCls:'icon-undo'" onclick="BatFun('statusbat',0);">无效</div>
			        <div data-options="iconCls:'icon-redo'" onclick="BatFun('statusbat',1);">有效</div>
			        <div data-options="iconCls:'icon-back'" onclick="BatFun('statusbat',2);">退回</div>
			        <div data-options="iconCls:'icon-lock'" onclick="BatFun('statusbat',3);">删除</div>
			    </div>

			    <a href="#" class="easyui-menubutton" data-options="menu:'#mm12',plain:true">处方</a>
		        <div id="mm12">
			    	<div data-options="iconCls:'ext-icon-pill'" onclick="BatFun('otctypebat',0);">非处方药</div>
			        <div data-options="iconCls:'ext-icon-pill'" onclick="BatFun('otctypebat',1);">处方药品</div>
			        <div data-options="iconCls:'ext-icon-pill'" onclick="BatFun('otctypebat',2);">医疗器械</div>
			        <div data-options="iconCls:'ext-icon-pill'" onclick="BatFun('otctypebat',3);">其它类型</div>
			    </div>

			     <a href="#" class="easyui-menubutton" data-options="menu:'#mm13',plain:true">医保</a>
		        <div id="mm13">
			    	<div data-options="iconCls:'ext-icon-pill'" onclick="BatFun('medicaltypebat',0);">甲类</div>
			        <div data-options="iconCls:'ext-icon-pill'" onclick="BatFun('medicaltypebat',1);">乙类</div>
			        <div data-options="iconCls:'ext-icon-pill'" onclick="BatFun('medicaltypebat',2);">非医保</div>
			    </div>
			</td>
		</tr>
		<tr>
			<td>
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-note_add',plain:true" onclick="addFun();">添加</a>
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-page_excel',plain:true" onclick="importFun();">导入</a>
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-page_white_excel',plain:true" onclick="exportFun();">导出</a>
			</td>
		</tr>
	</table>
</div>
</cfmodule>
<script type="application/javascript">
var importFun = function(){
	 var dialog = parent.fw.modalDialog({
        title: '导入数据',
        url: '?action=product.import',
        buttons: [
        {
            text: '导入数据',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid);
            }
        },{
            text: '关闭窗口',
            handler: function() {
               dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
}

var exportFun = function(){
	window.location.href= '?action=product.exportFile';
}

//批量记录操作
var BatFun = function(type,v){
	var url = "?action=product." + type;
	var rows = $('#grid').datagrid('getSelections');
	var ids = [];
	for(var i=0; i<rows.length; i++){
		ids.push(rows[i].id);
	}
	if(ids.length >0){
		$.post(url,
		{ids:ids.toString(),value:v},
		function() {
			grid.datagrid('reload');
		},'json');
	}else{
		 $.messager.show({title:'提示',msg:'请选择操作记录！',timeout:2000,showType:'slide'});
	}

}

//删除操作
var removeFun = function(id) {
    parent.$.messager.confirm('询问', '您确定要删除此记录？',
    function(r) {
        if (r) {
            $.post('?action=product.delete', {
                id: id
            },
            function(result) {
                grid.datagrid('reload');
            },
            'json');
        }
    });
};

//查看操作
var showFun = function(id) {
    var dialog = parent.fw.modalDialog({
        title: '查看记录',
        width:800,
        height:600,
        url: '?action=product.form&equipmenttype=<cfoutput>#rc.equipmenttype#</cfoutput>&id=' + id,
        buttons: [{
            text: '关闭窗口',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
};


//新增操作
var addFun = function() {
    var dialog = parent.fw.modalDialog({
        title: '新增记录',
        width:800,
        height:600,
        url: '?action=product.form&equipmenttype=<cfoutput>#rc.equipmenttype#</cfoutput>',
        buttons: [
        {
            text: '新增记录',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
            }
        },{
            text: '关闭窗口',
            handler: function() {
               dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
}
//修改操作
var editFun = function(id) {
    var dialog = parent.fw.modalDialog({
        title: '修改记录',
        width:800,
        height:600,
        url: '?action=product.form&equipmenttype=<cfoutput>#rc.equipmenttype#</cfoutput>&id=' + id,
        buttons: [
        {
            text: '修改记录',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
            }
        },{
            text: '关闭窗口',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
};

//单条记录操作
var singleFun = function(type,id) {
	var url = "?action=product." + type;
	$.post(url,
	{id:id},
	function() {
		grid.datagrid('reload');
	},'json');
};

$(function(){
	//列表操作
	var gird;
	grid = $('#grid').datagrid({
		fit: true,
		border:false,
		collapsible:false,
		pagination:true,
		singleSelect:false,
		rownumbers:true,
		sortName:'id',
		idField:'id',
		checkOnSelect:false,
		sortOrder:'desc',
		toolbar : '#toolbar',
		url:'?action=product.list&equipmenttype=<cfoutput>#rc.equipmenttype#</cfoutput>',
		columns:[[
			{field:'ck',checkbox:true},
			{field:'id',title:'ID',width:40,sortable:true},
			{field:'procode',title:'产品编号',width:80,sortable:true},
			{field:'prochsname',title:'产品名称',width:250,sortable:true},
			{field:'specification',title:'产品规格',width:120,sortable:true},
			{field:'approvalnumber',title:'批准文号',width:120,sortable:true},
			{field:'producingname',title:'生产厂家',width:200,sortable:true},
			{field:'marketprice',title:'市场价',width:80,sortable:true,align:'right',
				formatter : function(value, row) {
					return accounting.formatMoney(value);
				}
			},
			{field:'saleprice',title:'销售价',width:80,sortable:true,align:'right',
				formatter : function(value, row) {
					return accounting.formatMoney(value);
				}
			},
			{field:'status',title:'审核状态',width:60,sortable:true,align:'center',
				formatter : function(value, row) {
					var str ='';
					//1有效 0无效 2审核退回 3删除
					switch (value){
						case 0:
						str = '无效';
						break;
						case 1:
						str = '有效';
						case 2:
						str ='审核退回';
						break;
						case 3:
						str = '删除';
						break;
					}
					return str;
				}
			},
			{field:'issale',title:'销售状态',width:60,sortable:true,align:'center',
				formatter : function(value, row) {
					str ='';
					if(value == 0){
						str = '下架';
					}else{
						str = '上架';
					}
					return str;
				}
			},
			{
				title : '操作',
				field : 'action',
				align: 'center',
				width : '100',
				formatter : function(value, row) {
					var str = '';
						str += fw.formatString('<img class="iconImg ext-icon-note" title="查看" onclick="showFun(\'{0}\');"/>', row.id);
						str += fw.formatString('<img class="iconImg ext-icon-note_edit" title="编辑" onclick="editFun(\'{0}\');"/>', row.id);
						str += fw.formatString(' <img class="iconImg ext-icon-note_delete" title="删除" onclick="removeFun(\'{0}\');"/>', row.id);
					return str;
				}
			}
		]],
		onLoadSuccess : function(data) {
			$('.iconImg').attr('src', fw.pixel_0);
		}
	});


});
</script>